package mc.support.taobao.api;

import mc.support.taobao.api.fields.GetInventoryItemFields;
import com.taobao.api.TaobaoRequest;
import com.taobao.api.request.ItemsInventoryGetRequest;
import com.taobao.api.response.ItemsInventoryGetResponse;

import java.util.HashSet;
import java.util.Set;

/**
 * Created with IntelliJ IDEA. <br/>
 * Author: francis Yun    <br/>
 * Date: 2013-12-13  <br/>
 */
public class GetInventoryItemReq extends AbstractReq<GetInventoryItemReq, ItemsInventoryGetResponse> {

    private GetInventoryItemFields fields;
    private String q;
    private String banner;
    private Long cid;
    private Set<String> sellerCids;
    private Long pageNo;
    private Long pageSize;
    private Boolean hasDiscount;
    private String orderBy;

    public GetInventoryItemReq fields(GetInventoryItemFields fields) {
        this.fields = fields;
        return this;
    }

    public GetInventoryItemReq q(String q) {
        this.q = q;
        return this;
    }

    public GetInventoryItemReq cid(Long cid) {
        this.cid = cid;
        return this;
    }

    public GetInventoryItemReq pageNo(Long pageNo) {
        this.pageNo = pageNo;
        return this;
    }

    public GetInventoryItemReq banner(String banner) {
        this.banner = banner;
        return this;
    }

    public GetInventoryItemReq pageSize(Long pageSize) {
        this.pageSize = pageSize;
        return this;
    }

    public GetInventoryItemReq hasDiscount(Boolean hasDiscount) {
        this.hasDiscount = hasDiscount;
        return this;
    }

    public GetInventoryItemReq orderBy(String orderBy) {
        this.orderBy = orderBy;
        return this;
    }

    public GetInventoryItemReq sellerCids(Set<String> sellerCids) {
        this.sellerCids = sellerCids;
        return this;
    }

    public GetInventoryItemReq addSellerCid(String sellerCid) {
        if ( null == sellerCids ) {
            sellerCids = new HashSet<String>();
        }
        sellerCids.add( sellerCid );
        return this;
    }

    @Override
    protected TaobaoRequest toRequest() {

        ItemsInventoryGetRequest req = new ItemsInventoryGetRequest();

        if ( null != fields ) {
            req.setFields( fields.toString() );
        }

        if ( null != q ) {
            req.setQ( q );
        }

        if ( null != banner ) {
            req.setBanner( banner );
        }

        if ( null != cid ) {
            req.setCid( cid );
        }

        if ( null != sellerCids && sellerCids.size() > 0 ) {
            req.setSellerCids( setToString( sellerCids ) );
        }

        if ( null != pageNo ) {
            req.setPageNo( pageNo );
        }

        if ( null != pageSize ) {
            req.setPageSize( pageSize );
        }

        if ( null != hasDiscount ) {
            req.setHasDiscount( hasDiscount );
        }

        if ( null != orderBy ) {
            req.setOrderBy( orderBy );
        }

        return req;
    }

}
